/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Taxi.db;

import Taxi.model.Employee;
import java.sql.SQLException;
import java.util.List;
import net.sf.persist.Persist;

/**
 *
 * @author U24022
 */
public class EmployeeDAOPersist {
    
    Persist persist = null;

    public EmployeeDAOPersist() {
        this.persist = new Persist(Database.getConnection());
    }


    public int save(Employee employee) throws SQLException {
        return persist.insert(employee);
    }

    public int update(Employee employee) throws SQLException {
        return persist.update(employee);
    }

// sample UPDATE employee SET emp_num =2 WHERE emp_num =1 AND first_name ='Chan' AND last_name='Howard' AND address='129378 askhdao 1' AND birthday='2000-10-20' AND license='qiweju123734';
    public Employee getEmployeeByFirstName(String firstname) throws SQLException {
        return persist.read(Employee.class, "select * from employee where first_name = ?", firstname);
    }

    public void deleteByFirstName(String firstname) {
        try {
            persist.delete(getEmployeeByFirstName(firstname));
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public List<Employee> getAllEmployee() throws SQLException {
         return persist.readList(Employee.class);
    }
}
